42 Vowel Count 7 kyu


Posted by mijouhsieh on 2024-01-04

7 kyu Vowel Count

題目說明:

函式帶入字串判斷有幾個母音(a,e,i,o,u)

code
export class Kata {
  static getCount(str: string): number {
    //code
    const lowerCaseStr = str.trim().toLowerCase();
    const regex = /[aeiou]/g;
    const matches = lowerCaseStr.match(regex);

    if (matches) {
      return matches.length;
    } else {
      return 0;
    }
  }
}

#TypeScript #string.match() #RegEx







Related Posts

DE2_115(DAY3)以niosii去控制板子上的sdram

DE2_115(DAY3)以niosii去控制板子上的sdram

建立學習心態

建立學習心態

如何成為專家 - 技巧篇(尚未完成,先放出來供需要的朋友參考)

如何成為專家 - 技巧篇(尚未完成,先放出來供需要的朋友參考)


Comments